/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <cstdio>
#include <map>

using namespace std;

int main_1002()
{
    map<int,double,greater<int>> polynomial;
    int K,exponent,cnt=0;
    double coefficient;
    scanf("%d",&K);
    for (int i=0; i<K ; ++i)
    {
        scanf("%d%lf",&exponent,&coefficient);
        polynomial[exponent]+=coefficient;
    }
    scanf("%d",&K);
    for (int i=0; i<K ; ++i)
    {
        scanf("%d%lf",&exponent,&coefficient);
        polynomial[exponent]+=coefficient;
    }
    for (auto iter=polynomial.begin(); iter!=polynomial.end() ; ++iter )
    {
        if (iter->second)
        {
            ++cnt;
        }
    }
    printf("%d",cnt);
    for (auto iter=polynomial.begin(); iter!=polynomial.end() ; ++iter )
    {
        if (iter->second)
        {
            printf(" %d %.1lf",iter->first,iter->second);
        }
    }
    return 0;
}
